import logging
from aiogram.types import Message
from aiogram.dispatcher import FSMContext
from services.fipi import parse_guid, verify_is_answer_correct


async def check_answer_handler(message: Message, state: FSMContext):
    answer = message.text

    async with state.proxy() as data:
        question_url = data["question_url"]
        guid = await parse_guid(question_url)

        logging.info(guid)

        is_answer_correct = await verify_is_answer_correct(guid, answer)

    if is_answer_correct:
        await message.answer("Ответ верен!")
        await state.finish()
    else:
        await message.answer("Неверно! Попробуй ещё раз!")
